#include "rtthread.h"
#include "rtdevice.h"
#include "drv_led.h"

static const rt_base_t right_leds[] = {
    16,
    9,
    8,
};

static const rt_base_t left_leds[] = {
    17,
    29,
    30,
};

void ist_led_init(void)
{
    // 初始化所有引脚
    int i;
    for (i = 0; i < sizeof(left_leds) / sizeof(left_leds[0]); i++)
    {
        rt_pin_mode(left_leds[i], PIN_MODE_INPUT_PULLUP);
    }
    for (i = 0; i < sizeof(right_leds) / sizeof(right_leds[0]); i++)
    {
        rt_pin_mode(right_leds[i], PIN_MODE_INPUT_PULLUP);
    }
}

rt_uint8_t ist_led_get(void)
{
    rt_uint8_t ret = 0;
    int i;
    for (i = 0; i < sizeof(left_leds) / sizeof(left_leds[0]); i++)
    {
        if (rt_pin_read(left_leds[i]) != PIN_LOW)
        {
            ret |= (1 << (i + 4));
        }
    }
    for (i = 0; i < sizeof(right_leds) / sizeof(right_leds[0]); i++)
    {
        if (rt_pin_read(right_leds[i]) != PIN_LOW)
        {
            ret |= (1 << (3 - i));
        }
    }
    return ret;
}
